//
//  ShopTableHeaderView.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/7/28.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#import "ShopTableHeaderView.h"

@interface ShopTableHeaderView()

@property (nonatomic,weak) UIButton *lastSelectBtn;

@end
@implementation ShopTableHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        NSArray *titles = @[@"图文详情",@"产品参数",@"产品评论"];
        float btnW = (ScreenW-0.6)/3.0;
        for (NSInteger i=0; i<3; i++) {
            UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake((btnW+0.3)*i, 0, btnW, 50)];
            [btn setTitle:titles[i] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
            if (i != 2) {
                UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(btnW+(btnW+0.3)*i, 10, 0.3, 30)];
                lineView.backgroundColor = [UIColor lightGrayColor];
                [self.contentView addSubview:lineView];
            }
            btn.titleLabel.font = Font(15);
            if (i==0) {
                btn.selected = YES;
                self.lastSelectBtn = btn;
            }
            btn.tag = DetailTypeImageDetail+i;
            [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            [self.contentView addSubview:btn];
        }
    }
    return self;
}

- (void)btnClick:(UIButton *)btn
{
    if (btn == self.lastSelectBtn) return;
    self.lastSelectBtn.selected = NO;
    btn.selected = YES;
    self.lastSelectBtn = btn;
    if ([self.delegate respondsToSelector:@selector(shopTableHeaderViewChanged:)]) {
        [self.delegate shopTableHeaderViewChanged:(DetailType)btn.tag];
    }
}


@end
